package cloud.dandanit.itservice.service.impl;

import cloud.dandanit.itservice.entity.Banner;
import cloud.dandanit.itservice.mapper.BannerMapper;
import cloud.dandanit.itservice.service.BannerService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 首页banner表 服务实现类
 * </p>
 *
 * @author luokai
 * @since 2022-06-30
 */
@SuppressWarnings("UnnecessaryLocalVariable")
@Service
public class BannerServiceImpl extends ServiceImpl<BannerMapper, Banner> implements BannerService {

    /**
     * 获取首页
     * key需要再加引号 @Cacheable
     * @return 幻灯片列表
     */
    @Override
    @Cacheable(key="'bannerList'", value = "banner")
    public List<Banner> getIndexBannerList() {

        LambdaQueryWrapper<Banner> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(Banner::getState, 1)
                    .orderByDesc(Banner::getSort)
                    .last("limit 8");

        List<Banner> bannerList = this.list(queryWrapper);

        return bannerList;
    }
}
